//priority 10000
let funs = []

ServerEvents.tick(event => {
    event.server.entities.forEach(entity => {
        funs.forEach(fun => {
            fun(entity)
        })
    })
    updateSchedule()
})

const severEntityUpdater = {
    EntityTick(/** @type {(handler: Internal.Entity) => void} */ entity) {
        funs.push(entity)
    }
}

function updateSchedule() {
    /**@type {Internal.Iterator<any>}*/
    var iterator = global.Schedule.iterator()
    while (iterator.hasNext()) {
        var runable = iterator.next()
        runable.tick()
        if (runable.finish) {
            iterator.remove()
        }
    }
}